package com.zst.stream;

import com.zst.stream.message.MessageSource;
import com.zst.stream.message.StringMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableBinding(Source.class)
@RestController
@RequestMapping("/")
public class MqDemoApplication {

	@Autowired
	@Output(Source.OUTPUT)
	private MessageChannel messageChannel;

	@RequestMapping("sendMessage")
	public String sendMessage(){
		StringMessage message = new StringMessage();
		message.setMessage("Trancend");
		messageChannel.send(MessageBuilder.withPayload(message).build());
		return "Sended";
	}

	public static void main(String[] args) {
		SpringApplication.run(MqDemoApplication.class, args);
	}

}
